package com.gzh;

import com.gzh.config.MyConfig;
import com.gzh.pojo.Pet;
import com.gzh.pojo.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class HelloWordApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(HelloWordApplication.class, args);
        String[] names = run.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }

        //3、从容器中获取组件

        Pet tom01 = run.getBean("tom", Pet.class);

        Pet tom02 = run.getBean("tom", Pet.class);

        System.out.println("组件："+(tom01 == tom02));

        MyConfig bean = run.getBean(MyConfig.class);
        System.out.println(bean);


        System.out.println("---------------------------------");


        User user01 = run.getBean("user01",User.class);
        Pet pet = run.getBean("tom",Pet.class);
        System.out.println(user01.getPet() == pet);



    }
}
